﻿using Microsoft.EntityFrameworkCore.Internal;
using System.Linq;

namespace WebApI0001.DoMain.Entity
{
    public class DbInitializeHelper
    {
        public static void Initialize()
        {
            using (var db = new Admin0001DbContext())
            {
                db.Database.EnsureCreated();

                var y = db.Brands.Any();
                if (!y)
                {
                    var brand = new Brand
                    {
                        BrandName = "小米sj",
                        Description = "国产最具性价比的手机品牌"
                    };

                    var brand1 = new Brand { BrandName = "耐克", Description = "全國連鎖鞋墊" };
                   
                    db.Brands.Add(brand);
                    db.SaveChanges();
                    db.Brands.Add(brand1);

                    db.SaveChanges();

                    var category = new Category
                    { CategoryName = "数码类" };

                    var category1 = new Category { CategoryName = "鞋類" };

                    db.Categories.Add(category);
                    db.SaveChanges();
                    db.Categories.Add(category1);

                    db.SaveChanges();

                    db.ProDucks.AddRange(new ProDuck[]
                        {
                        new ProDuck
                        {
                            ProduckName ="小米10黑色",
                            ShortDesc = "高端機",
                            FullDesc = "突破科技的拍照游戲手機",
                            BrandId =brand.Id,
                            CategoryId=category.Id
                        },
                        new ProDuck
                        {
                             ProduckName ="小米10紅色",
                            ShortDesc = "??????",
                            FullDesc = "?????????",
                            BrandId =brand.Id,
                            CategoryId = category.Id
                        },
                        new ProDuck
                        {
                            ProduckName = "耐克籃球鞋",
                            ShortDesc ="很貴",
                            FullDesc ="非土豪者不建議入手",
                            BrandId = brand1.Id,
                            CategoryId = category1.Id
                        },
                        new ProDuck
                        {
                            ProduckName = "耐克休閑鞋",
                            ShortDesc ="很貴",
                            FullDesc ="同上",
                            BrandId = brand1.Id,
                            CategoryId = category1.Id
                        }

                        });
                    db.SaveChanges();
                }
               
            }
        }
    }
}
